var koa = require("koa");
var Router = require("koa-router");
var views = require("koa-views");
var bodyParser = require("koa-bodyparser");
var koaStatic = require("koa-static");
var render = require('koa-art-template');
var path = require("path");


var app = new koa();
var router = new Router();



app.use(views('static',{
    map:{html:'ejs'}
}));

// app.use(static('static'));
app.use(koaStatic(__dirname + '/static'));

//配置 post bodyparser 中间件
app.use(bodyParser());

//配置 koa-art-template 模板引擎
render(app, {
    root: path.join(__dirname, 'views'), //视图位置
    extname: '.html',                    //后缀名
    debug: process.env.NODE_ENV !== 'production'//是否开启 debug 模式
});


router.get('/', async (ctx) => {
    var list = {name:"zhangsan"}
    await ctx.render('index',{list})

});
router.get('/news', async (ctx) => {
    await ctx.render('news')

});

// 接收post提交的数据

router.post('/doAdd', async (ctx)=>{
    ctx.body = ctx.request.body;
});




app.use(router.routes());
app.use(router.allowedMethods);


app.listen(3000);


